<?php
/**
 * Created by PhpStorm.
 * User: Steven
 * Date: 2017/5/18
 */

namespace app\classes\model;


use think\Model;

class AuditionModel extends Model
{
    public function __construct($data = [])
    {
        parent::__construct($data);
    }


    /**
     * 通过条件获取试听信息
     * @param array $filter
     * @return array|false|\PDOStatement|string|Model
     */
    public function getAuditionByField($filter=[])
    {
        //默认条件
        $where = [];
        if(!empty($filter) && is_array($filter)){
            $where = array_merge($where,$filter);
        }

        $obj = $this->alias('a')
            ->field('a.*,sc.name as school_name,cl.name as class_name,co.course_name,st.name as student_name,
            u.mobile,u.user_login as parent_name')
            ->join('school sc', 'a.school_id=sc.id')
            ->join('student st', 'a.student_id=st.id')
            ->join('user u', 'a.parent_id=u.id')
            ->join('class cl', 'a.class_id=cl.id')
            ->join('course co', 'a.course_id=co.id')
            ->where($where)
            ->find();

        return $obj;
    }
}